import React, {Component} from 'react';

class Count extends Component {


    // 加
    increment=()=>{
        const {increment}=this.props
        const {value}=this.selectNum
        increment(value)

    }
    // 减
    decrement=()=>{
        const {decrement}=this.props
        const {value}=this.selectNum
        decrement(value)

    }
    // 奇数再加
    incrementIfOdd=()=>{
        const {count}=this.props
        if(count%2!==0){
            const {increment}=this.props
            const {value}=this.selectNum
            increment(value)
        }

    }
    // 异步加
    incrementAsync=()=>{
        const {incrementAsync}=this.props
        const {value}=this.selectNum
        incrementAsync(value,1000)

    }

    render() {
        const {count}=this.props
        return (
            <div>
                <h1>当前求和为:{count}</h1>
                <select ref={c=>this.selectNum=c}>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <button onClick={this.increment}>+</button>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <button onClick={this.decrement}>-</button>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <button onClick={this.incrementIfOdd}>奇数再+</button>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <button onClick={this.incrementAsync}>异步+</button>
            </div>

        );
    }
}

export default Count;